#include "testplot.h"
#include <QtWidgets/QApplication>
#include "PlotView.h"
void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
    QByteArray localMsg = msg.toLocal8Bit();
    const char* file = context.file ? context.file : "";
    const char* function = context.function ? context.function : "";

    switch (type) {
    case QtDebugMsg:
        fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtInfoMsg:
        fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtWarningMsg:
        fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtCriticalMsg:
        fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtFatalMsg:
        fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    }
}
int main(int argc, char *argv[])
{
    qInstallMessageHandler(customMessageHandler);
    QApplication a(argc, argv);
    //testPlot w;
    PlotView w(nullptr);
    w.resize(800, 600);
    for (size_t i = 1; i < 5; i++)
    {
        QSharedPointer<QCPGraphDataContainer> data(new QCPGraphDataContainer);
        for (int j = 0; j < 100; j++)
        {
            data->add(QCPGraphData(j, 20 * i * cos((i * 5 + j) / 30.0 * 3.14)));
        }
        w.add_plotData(data, "name" + QString::number(i));
        w.setPlotStatus((uint64_t) (data.data()), true);
    }
    
    w.show();
    //w.show();
    return a.exec();
}
